package com.hou.controller;

import com.hou.pojo.Grade;
import com.hou.pojo.Result;
import com.hou.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shkstart
 * @create 2021-09-29-20:27
 */
@RestController
@RequestMapping("grade")
@CrossOrigin
public class GradeController {
    @Autowired
    GradeService gradeService;

    // 查询所有成绩
    @GetMapping("AllGrade")
    public List getAllGrade(){
        List allGrade = gradeService.getAllGrade();
        return allGrade;
    }

    // 用户成绩
    @GetMapping("userGrade")
    public List getUserGrade(Integer id){
        List userGrade = gradeService.getUserGrade(id);
        return userGrade;
    }

    // 添加成绩
     @PostMapping("addGrade")
    public Result addGrade(@RequestBody Grade grade){
         System.out.println(grade);
         Result result = new Result();
         if (gradeService.addGrade(grade)){
             result.setMsg("添加成功");
         } else {
             result.setRESULT(false).setMsg("添加失败");
         }
         return result;
     }
}
